{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "import plotly as py\n",
    "from plotly.graph_objs import Scatter,Layout,Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv(\"travel_area.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2011</th>\n",
       "      <th>2012</th>\n",
       "      <th>2013</th>\n",
       "      <th>2014</th>\n",
       "      <th>2015</th>\n",
       "      <th>2016</th>\n",
       "      <th>2017</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地区</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>华北地区</th>\n",
       "      <td>8857.34</td>\n",
       "      <td>9412.55</td>\n",
       "      <td>9756.71</td>\n",
       "      <td>9417.98</td>\n",
       "      <td>9664.61</td>\n",
       "      <td>10635.69</td>\n",
       "      <td>11055.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>东北地区</th>\n",
       "      <td>4016.04</td>\n",
       "      <td>4593.94</td>\n",
       "      <td>4633.87</td>\n",
       "      <td>2765.46</td>\n",
       "      <td>2765.46</td>\n",
       "      <td>3073.18</td>\n",
       "      <td>3023.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>华东地区</th>\n",
       "      <td>23725.26</td>\n",
       "      <td>26141.41</td>\n",
       "      <td>22507.60</td>\n",
       "      <td>24027.07</td>\n",
       "      <td>27463.95</td>\n",
       "      <td>26166.42</td>\n",
       "      <td>28752.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中南地区</th>\n",
       "      <td>17837.77</td>\n",
       "      <td>19980.30</td>\n",
       "      <td>20864.44</td>\n",
       "      <td>21523.93</td>\n",
       "      <td>23203.26</td>\n",
       "      <td>24614.75</td>\n",
       "      <td>27098.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西南地区</th>\n",
       "      <td>3435.20</td>\n",
       "      <td>4188.19</td>\n",
       "      <td>4780.54</td>\n",
       "      <td>4966.26</td>\n",
       "      <td>5932.93</td>\n",
       "      <td>6790.37</td>\n",
       "      <td>7425.24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          2011      2012      2013      2014      2015      2016      2017\n",
       "地区                                                                        \n",
       "华北地区   8857.34   9412.55   9756.71   9417.98   9664.61  10635.69  11055.67\n",
       "东北地区   4016.04   4593.94   4633.87   2765.46   2765.46   3073.18   3023.43\n",
       "华东地区  23725.26  26141.41  22507.60  24027.07  27463.95  26166.42  28752.58\n",
       "中南地区  17837.77  19980.30  20864.44  21523.93  23203.26  24614.75  27098.71\n",
       "西南地区   3435.20   4188.19   4780.54   4966.26   5932.93   6790.37   7425.24"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=df.set_index(\"地区\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['华北地区', '东北地区', '华东地区', '中南地区', '西南地区', '西北地区'], dtype='object', name='地区')"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['2011', '2012', '2013', '2014', '2015', '2016', '2017'], dtype='object')"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2011, 2012, 2013, 2014, 2015, 2016, 2017]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[int(x) for x in df.columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2011     8857.34\n",
       "2012     9412.55\n",
       "2013     9756.71\n",
       "2014     9417.98\n",
       "2015     9664.61\n",
       "2016    10635.69\n",
       "2017    11055.67\n",
       "Name: 华北地区, dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['华北地区',:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'华北地区'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['华北地区',:].name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 8857.34,  9412.55,  9756.71,  9417.98,  9664.61, 10635.69,\n",
       "       11055.67])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['华北地区',:].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['2011', '2012', '2013', '2014', '2015', '2016', '2017'], dtype='object')"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['华北地区',:].index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "trace0 = Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"华北地区\",:].values\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'output_huabei.html'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "py.offline.plot([trace0],filename = 'output_huabei.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "import plotly as py\n",
    "import plotly.graph_objs as go\n",
    "pyplt=py.offline.plot\n",
    "\n",
    "华北地区 = go.Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"华北地区\",:].values,\n",
    "    name='华北地区'\n",
    ")\n",
    "\n",
    "东北地区 = go.Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"东北地区\",:].values,\n",
    "    name='东北地区'\n",
    ")\n",
    "\n",
    "中南地区 = go.Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"中南地区\",:].values,\n",
    "    name='中南地区'\n",
    ")\n",
    "\n",
    "西南地区 = go.Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"西南地区\",:].values,\n",
    "    name='西南地区'\n",
    ")\n",
    "\n",
    "华东地区 = go.Scatter(\n",
    "    x=[int(x) for x in df.columns],\n",
    "    y=df.loc[\"华东地区\",:].values,\n",
    "    name='华东地区'\n",
    ")\n",
    "\n",
    "layout = dict(xaxis=dict(rangeselector=dict(visible=True,\n",
    "                                           buttons=list([  dict(count=1,\n",
    "                                                                label='1',\n",
    "                                                                ),\n",
    "                                                           dict(count=5,\n",
    "                                                                label='5',\n",
    "                                                                ),\n",
    "                                                           dict(step=\"all\")\n",
    "                                                        ])\n",
    "                                           ),\n",
    "                        rangeslider=dict(),\n",
    "                        title='年份'\n",
    "                        ),\n",
    "             yaxis=dict(title=\"旅游收入\"),\n",
    "             title='年度旅游收入'\n",
    "             )\n",
    "\n",
    "fig = dict(data=[华北地区,东北地区,中南地区,西南地区,华东地区],layout=layout)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'年度旅游收入.html'"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pyplt(fig,filename='年度旅游收入.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
